<?php
class Presentation {

  private $smarty;
  private $theApp;

  function __construct($appHandle = null) {
    $this->theApp                = $appHandle;
    require_once $this->theApp->config->absolutePath . 'libs/Smarty.class.php';
    $this->smarty                = new Smarty;
    $this->smarty->compile_check = true;
    $this->smarty->debugging     = false;
    $this->smarty->template_dir  = $this->theApp->config->absolutePath . "templates";
    $this->smarty->compile_dir   = $this->theApp->config->absolutePath . "templates_c";
    $this->smarty->config_dir    = $this->theApp->config->absolutePath . "configs";
  }


  public function invalidSession($title) {
    $this->smartyDefaultAssigns($title);
    $this->smarty->display('invalid_session.tpl');
  }
  
  function information($title,$info) {
    $this->smartyDefaultAssigns($title);
    $this->smarty->assign("info",$info);
    $this->smarty->display('information.tpl');
  }

  function welcome($title,$dataOffer,$dataInvoice, $workItems, $customers,$minMaxDates) {
    $this->smartyDefaultAssigns($title);
    $this->smarty->assign("dataO",$dataOffer);
    $this->smarty->assign("dataI",$dataInvoice);
    $this->smarty->assign("workItems",$workItems);
    $this->smarty->assign("customers",$customers);
    $this->smarty->assign("minMaxDates",$minMaxDates);
    $this->smarty->display("welcome.tpl");  
  }
  
  function renderReport($title,$workItems,$customers,$reportData,$totalSum) {
    $this->smartyDefaultAssigns($title);
    $this->smarty->assign("workItems",$workItems);
    $this->smarty->assign("customers",$customers);
    $this->smarty->assign("from",$_POST['from']);
    $this->smarty->assign("to",$_POST['to']);
    $this->smarty->assign("rData",$reportData);
    $this->smarty->assign("totalSum",$totalSum);
    $this->smarty->display("report.tpl");  
  }
  
  private function smartyDefaultAssigns($title) {
    $this->smarty->assign("title", $title);
  }
  
  function freeHTML($content,$title="Title") {
    $this->smarty->assign("HTMLContent",$content);
	$this->smarty->assign("HTMLTitle",$title);
    $this->smarty->display('freeHTML.tpl');
  }
    
  function errorHandler($message) {
	$this->smarty->assign("HTMLTitle","Fehler");
    $this->smarty->assign("ErrorMessage",$message);
    $this->smarty->display('error.tpl');
  }

  public function __toString() {
    return "A hearty 'Hello' from Presentation Layer.";
  }
}
